package com.mini.cn.goods.servlet.ws.serializer;

import com.alibaba.fastjson.JSONObject;

/**
 * Created with IntelliJ IDEA.

 * User: fly
 * Date: 2020-05-15
 * Time: 2:24 下午
 */
public class JsonSerializer implements ISerializer {

    @Override
    public byte getSerializerAlgorithm() {
        return ISerializer.JSON;
    }

    @Override
    public byte[] serializeBytes(Object object) {
        return JSONObject.toJSONBytes(object);
    }

    @Override
    public String serializeString(Object object) {
        return JSONObject.toJSONString(object);
    }

    @Override
    public <T> T deserialize(Class<T> clazz, byte[] bytes) {
        return JSONObject.parseObject(bytes, clazz);
    }

    @Override
    public <T> T deserialize(Class<T> clazz, String content) {
        return JSONObject.parseObject(content, clazz);
    }
}
